<%= header %>
<%= boomerangScript %>
<script src="../../vendor/angular/angular.js"></script>
<base href="/pages/05-angular/17-wait.html" />
<script src="../../vendor/angular-resource/angular-resource.js"></script>
<script src="../../vendor/angular-route/angular-route.js"></script>
<script src="support/app.js"></script>
<div id="output"></div>
<div ng-app="app">
	<div ng-view>
	</div>
</div>
<script src="/test-templates/spa/17-wait.js" type="text/javascript"></script>
<script src="17-wait.js" type="text/javascript"></script>
<script>
window.angular_imgs = [-1];

window.angular_html5_mode = true;

//
// Routes:
// 1. Home page (hard nav) - Filter: n/a, (hard navs can't be filtered, doesn't wait)
// 2. Home page (soft nav) - Filter: true, takes: 5 seconds (fires after resource)
// 3. Home page (soft nav) - Filter: true, takes: 1 ms (fires before resource)
// 4. Home page (soft nav) - Filter: false (doesn't wait)
//
window.angular_nav_routes = ["/widgets/1", "/widgets/2", "17-wait.html"];

// how long we should wait for each route
var routeWaits = [
	// spa_hard isn't filtered
	5000,
	1,
	0
];

// we'll put the end timestamps of each route in here so we can validate against beacons
window.spaWaitCompleteTimes = [];

// current route number
var routeNumber = 0;

// callback for each route
window.angular_route_wait = function() {
	if (routeWaits[routeNumber]) {
		setTimeout(function() {
			window.spaWaitCompleteTimes.push(BOOMR.now());

			// call complete 5 seconds afterward route start
			BOOMR.plugins.SPA.wait_complete();
		}, routeWaits[routeNumber]);

		routeNumber++;

		return true;
	}
	else {
		// not waiting for this route
		return false;
	}
};

BOOMR_test.init({
	testAfterOnBeacon: BOOMR.plugins.AutoXHR ? 4 : 1,
	Angular: {
		enabled: true
	},
	instrument_xhr: true,
	autorun: false
});
</script>
<%= footer %>
